package top.shiyiri.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author Aunean
 * @date 2022/2/10 16:41
 */
public class Filter1 implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    /**
     * Filter执行的顺序和web.xml中配置的顺序有关
     * 所有filter和目标资源默认都执行在同一个线程中
     * 多个Filter共同执行的时候，共用同一个request对象
     * @param servletRequest
     * @param servletResponse
     * @param filterChain
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("Filter1 前置代码");
        System.out.println("Filter1 线程：" + Thread.currentThread().getName());
        System.out.println("Filter1：" + servletRequest.getParameter("username"));
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("Filter1 后置代码");
    }

    @Override
    public void destroy() {

    }
}
